<template>
  <div class="login-passwd-container">
    <m-header title="提现密码"></m-header>
    <div class="input-wrapper">
      <div class="label">旧密码：</div>
      <div class="comp">
        <input v-model="oldPwd" :type="[showPwd?'text':'password']" placeholder="请输入6位数字密码">
        <div class="view" :class="{'no': !showPwd}" @click="showPwd=!showPwd">
          <span class="icon"></span>
        </div>
      </div>
    </div>
    <div class="input-wrapper">
      <div class="label">新密码：</div>
      <div class="comp">
        <input v-model="newPwd" :type="[showNewPwd?'text':'password']" placeholder="请输入6位数字新密码">
        <div class="view" :class="{'no': !showNewPwd}" @click="showNewPwd=!showNewPwd">
          <span class="icon"></span>
        </div>
      </div>
    </div>
    <div class="button-wrapper">
      <div class="btn" @click="handleSubmit">确定</div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex';

export default {
  data () {
    return {
      showPwd: false,
      showNewPwd: false,
      oldPwd: '',
      newPwd: ''
    };
  },
  methods: {
    ...mapActions({
      resetWithdrawPsw: 'mine/resetWithdrawPsw'
    }),
    handleSubmit () {
      if (!this.oldPwd) {
        this.$vux.toast.text('请输入当前提现密码');
        return false;
      } else if (this.oldPwd.length !== 6 || !/^\d{6}/gi.test(this.oldPwd)) {
        this.$vux.toast.text('请输入6位数字旧密码');
        return false;
      }

      if (!this.newPwd) {
        this.$vux.toast.text('请输入新密码');
        return false;
      } else if (this.newPwd.length !== 6 || !/^\d{6}/gi.test(this.newPwd)) {
        this.$vux.toast.text('请输入6位数字新密码');
        return false;
      }
      const params = {
        old_password: this.oldPwd,
        password: this.newPwd
      };
      // 缺少提现密码接口
      this.resetWithdrawPsw(params).then(res => {
        if (res) {
          this.$vux.toast.text('密码重置成功');
          setTimeout(() => {
            this.$router.replace({ path: '/setting' });
          }, 1500);
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.login-passwd-container {
  padding-top: 0.92rem;
  padding-bottom: 0.2rem;
  background: #f7f7f7;

  .input-wrapper {
    .label {
      font-size: 0.28rem;
      color: #666666;
      padding: 0.3rem 0 0.2rem 0.2rem;
    }
    .comp {
      height: 0.8rem;
      background: #ffffff;
      position: relative;
      input {
        width: 100%;
        padding: 0.1rem 0.6rem 0.1rem 0.3rem;
        height: 0.8rem;
        line-height: 0.8rem;
        box-sizing: border-box;
        &::-webkit-input-placeholder {
          // font-size: 0.28rem;
          color: #999999;
        }
      }
      .view {
        position: absolute;
        top: 0.12rem;
        right: 0.2rem;
        padding: 0.1rem;
        .icon {
          display: block;
          width: 0.36rem;
          height: 0.36rem;
          background-size: 100%;
          background-repeat: no-repeat;
          background-position: center center;
          background-image: url("../../../assets/imgs/login/icon-view@2x.png");
        }
        &.no .icon {
          background-image: url("../../../assets/imgs/login/icon-noview@2x.png");
        }
      }

      .hidden-passwd {
        width: 0.32rem;
        height: 0.14rem;
        position: absolute;
        top: 0.4rem;
        right: 0.2rem;
      }
      .show-passwd {
        width: 0.32rem;
        height: 0.27rem;
        position: absolute;
        top: 0.3rem;
        right: 0.2rem;
      }
    }
  }
  .button-wrapper {
    margin-top: 0.6rem;
    padding: 0 0.2rem;
    .btn {
      text-align: center;
      height: 0.88rem;
      line-height: 0.88rem;
      font-size: 0.34rem;
      color: #ffffff;
      background: #d44743;
      cursor: pointer;
      border-radius: 0.1rem;
    }
  }
}
</style>
